#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 25;

int n;
string words[N];
char c;
int g[N][N];
int cnt[N];
int contact(string& s, string& t) {
  int n1 = s.size(), n2 = t.size();
  int mx = min(n1, n2) - 1;
  rep(i, 1, mx) {
    if (s.substr(n1 - i) == t.substr(0, i)) return n2 - i;
  }
  return 0;
}
int ans;
void dfs(int i, int len) {
  ans = max(ans, len);
  rep(j, 1, n) {
    if (cnt[j] && g[i][j]) {
      cnt[j]--;
      dfs(j, len + g[i][j]);
      cnt[j]++;
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> words[i];
  cin >> c;
  rep(i, 1, n) rep(j, 1, n) { g[i][j] = contact(words[i], words[j]); }
  rep(i, 1, n) cnt[i] = 2;
  rep(i, 1, n) {
    if (words[i][0] == c) {
      cnt[i]--;
      dfs(i, words[i].size());
      cnt[i]++;
    }
  }
  cout << ans;
  return 0;
}